﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Company.PackageExtjs.ColorItem
{
    using System.Drawing;

    public class ColorItemDescriptionList
    {
        public List<ColorItemDescription> List { get; set; }
 
        public ColorItemDescriptionList()
        {
            List = new List<ColorItemDescription>
                {
                    new ColorItemDescription { Name = "Comment", Color = Color.Green },
                    new ColorItemDescription { Name = "MultiLineComment", Color = Color.Green },
                    new ColorItemDescription { Name = "ObjectAccessPath", Color = Color.Blue },
                    new ColorItemDescription { Name = "(", Color = Color.Blue },
                    new ColorItemDescription { Name = ")", Color = Color.Blue },
                    new ColorItemDescription { Name = "{", Color = Color.Blue },
                    new ColorItemDescription { Name = "}", Color = Color.Blue },
                    new ColorItemDescription { Name = "[", Color = Color.Blue },
                    new ColorItemDescription { Name = "]", Color = Color.Blue },
                    new ColorItemDescription { Name = "string", Color = Color.IndianRed },
                    new ColorItemDescription { Name = "ObjectAccessPathSingleElementParametrs?", Color = Color.Gray },
                    new ColorItemDescription { Name = "ObjectElement", Color = Color.Olive },
                    new ColorItemDescription { Name = "if", Color = Color.Blue },
                    new ColorItemDescription { Name = "var", Color = Color.Blue },
                    new ColorItemDescription { Name = "true", Color = Color.Blue },
                    new ColorItemDescription { Name = "this", Color = Color.Blue },
                    new ColorItemDescription { Name = "false", Color = Color.Blue }
                };
        }

        public Color GetColor(Irony.Parsing.ParseTreeNode node)
        {
            ColorItemDescription element;
            element = node.Term.Name.Equals("name") 
                ? this.List.FirstOrDefault(p => p.Name.Equals(node.Token.Text)) 
                : this.List.FirstOrDefault(p => p.Name.Equals(node.Term.Name));            
            return element != null ? element.Color : Color.Black;
        }
    }
}
